﻿@model ShippingByWeightModel
@using Nop.Plugin.Shipping.ByWeight.Models;
@using Telerik.Web.Mvc.UI;
@using Nop.Web.Framework;
@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)

@if (ViewBag.RefreshPage == true)
{
    <script type="text/javascript">
        try {window.opener.document.forms['@(ViewBag.formId)'].@(ViewBag.btnId).click();}
        catch (e){} 
        window.close();
    </script>
}

<script type="text/javascript">
    $(function () {
        $("#@Html.FieldIdFor(model => model.CountryId)").change(function () {
            var selectedItem = $(this).val();
            var ddlStates = $("#@Html.FieldIdFor(model => model.StateProvinceId)");
            $.ajax({
                cache: false,
                type: "GET",
                url: "@(Url.Action("GetStatesByCountryId", "Country", new RouteValueDictionary() { { "area", "Admin" } }))",
                data: { "countryId": selectedItem, "addAsterisk": "true" },
                success: function (data) {
                    ddlStates.html('');
                    $.each(data, function (id, option) {
                        ddlStates.append($('<option></option>').val(option.id).html(option.name));
                    });
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert('Failed to retrieve states.');
                }
            });
        });
    });
</script>

<table class="adminContent">
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.StoreId):
        </td>
        <td class="adminData">
            @Html.DropDownListFor(model => model.StoreId, Model.AvailableStores)
            @Html.ValidationMessageFor(model => model.StoreId)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.CountryId):
        </td>
        <td class="adminData">
            @Html.DropDownListFor(model => model.CountryId, Model.AvailableCountries)
            @Html.ValidationMessageFor(model => model.CountryId)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.StateProvinceId):
        </td>
        <td class="adminData">
            @Html.DropDownListFor(model => model.StateProvinceId, Model.AvailableStates)
            @Html.ValidationMessageFor(model => model.StateProvinceId)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.Zip):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.Zip)
            @Html.ValidationMessageFor(model => model.Zip)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.ShippingMethodId):
        </td>
        <td class="adminData">
            @Html.DropDownListFor(model => model.ShippingMethodId, Model.AvailableShippingMethods)
            @Html.ValidationMessageFor(model => model.ShippingMethodId)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.From):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.From) [@Model.BaseWeightIn]
                @Html.ValidationMessageFor(model => model.From)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.To):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.To) [@Model.BaseWeightIn]
            @Html.ValidationMessageFor(model => model.To)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.AdditionalFixedCost):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.AdditionalFixedCost) [@Model.PrimaryStoreCurrencyCode]
            @Html.ValidationMessageFor(model => model.AdditionalFixedCost)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.LowerWeightLimit):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.LowerWeightLimit)
            @Html.ValidationMessageFor(model => model.LowerWeightLimit)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.RatePerWeightUnit):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.RatePerWeightUnit) [@Model.PrimaryStoreCurrencyCode]
            @Html.ValidationMessageFor(model => model.RatePerWeightUnit)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.PercentageRateOfSubtotal):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.PercentageRateOfSubtotal)
            @Html.ValidationMessageFor(model => model.PercentageRateOfSubtotal)
        </td>
    </tr>
</table>
